package com.quick.controller;

import com.quick.base.Page;
import com.quick.base.Search;
import com.quick.blog.dto.BlogArticleDTO;
import com.quick.blog.search.BlogArticleSearch;
import com.quick.blog.vo.BlogArticleVo;
import com.quick.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/article")
@Api(tags = "博客文章")
public class ArticleController {

    @Resource
    private IArticleService articleService;
    
    @PostMapping("hots")
    @ApiOperation("查询文章分页列表")
    public List<BlogArticleVo> hots(){
		return articleService.hots();
    }

    @PostMapping("search")
    @ApiOperation("查询文章分页列表")
    public Page<BlogArticleVo> search(@RequestBody Search<BlogArticleSearch> search){
        return  articleService.search(search);
    }

    @PostMapping("addArticle")
    @ApiOperation("新增/更新文章")
    public Boolean addArticle(@RequestBody BlogArticleDTO article){
        return articleService.save(article);
    }

    @GetMapping("query/{id}")
    @ApiOperation("查询文章")
    public BlogArticleVo queryById(@PathVariable("id") BigInteger id){
        return articleService.queryById(id);
    }

    @PostMapping("batchDel")
    @ApiOperation("批量刪除")
    public Boolean batchDel(@RequestBody List<Long> ids){
        return  articleService.batchDel(ids);
    }


}
